<?php
/*
  This page presents a final summary and allows the user to launch a little window that
  provides details in a printable format.
*/
?>

<?php
  if (!isset($_COOKIE['ys-parcelNum'])) {
    setcookie('noParcelNum',true);
    $u = explode('/',$_SERVER['REQUEST_URI']);
    array_pop($u);
    $u = 'http://'.$_SERVER['SERVER_NAME'].implode('/',$u).'/?page=introLocation';
    header('Location: '.$u);
  }
  else if (!isset($_COOKIE['ys-pollution'])) {
    setcookie('noPollution',true);
    $u = explode('/',$_SERVER['REQUEST_URI']);
    array_pop($u);
    $u = 'http://'.$_SERVER['SERVER_NAME'].implode('/',$u).'/?page=introPollution';
    header('Location: '.$u);
  }
  $isRegistered = isset($_SESSION['gdusername']) AND isset($_SESSION['gdpassword']);

  $thumbnail = 'img/blank.png';
  if (isset($_COOKIE['ys-parcelThumbnail'])) {
    $thumbnail = substr($_COOKIE['ys-parcelThumbnail'],2);
  }
?>

<body onload="Ext.onReady(function(){init()})">
  <script>
      var print = function() {
        alert("Sorry, but the system is not quite ready yet.  Please try again.");
      };
      var cp;
      var parcelInfoStore;

      function init() {
        Ext.QuickTips.init();

        cp = new Ext.state.CookieProvider({
          expires : new Date(new Date().getTime()+(1000*60*60*24*30)) //30 days
        });
        Ext.state.Manager.setProvider(cp);

        // create a fake parcelInfoStore based on cookies
        parcelInfoStore = new Ext.data.ArrayStore({
          fields : [
             'Regulated'
            ,'Owner Name'
            ,'Phys Addr1'
            ,'Phys City'
            ,'Dep2HWT (in)'
            ,'Dep2ResLyr (in)'
            ,'Hyd Soil Group'
            ,'KSat (in/hr)'
            ,'Imperv Area (ac)'
            ,'UpLand Area (ac)'
            ,'Wetland Area (ac)'
            ,'Total Area (ac)'
            ,'Perv Load (lb/yr)'
            ,'Imperv Load'
            ,'Total Load (lb/yr)'
            ,'Slope (%)'
            ,'Load Credit/Deficit (lb/yr)'
          ]
          ,data : [[
             cp.get('parcelRegulated')
            ,cp.get('parcelOwner Name')
            ,cp.get('parcelPhys Addr1')
            ,cp.get('parcelPhys City')
            ,cp.get('parcelDep2HWT (in)')
            ,cp.get('parcelDep2ResLyr (in)')
            ,cp.get('parcelHyd Soil Group')
            ,cp.get('parcelKSat (in/hr)')
            ,cp.get('parcelImperv Area (ac)')
            ,cp.get('parcelUpLand Area (ac)')
            ,cp.get('parcelWetland Area (ac)')
            ,cp.get('parcelTotal Area (ac)')
            ,cp.get('parcelPerv Load (lb/yr)')
            ,cp.get('parcelImperv Load')
            ,cp.get('parcelTotal Load (lb/yr)')
            ,cp.get('parcelSlope (%)')
            ,cp.get('parcelLoad Credit/Deficit (lb/yr)')
          ]]
        });

        // Show the summary info in a new window.
        print = function() {
          new Ext.ux.ManagedIFrame.Window({
             defaultSrc  : 'popup.php'
               + '?subtitle0=Site Information'
               + '&parcelNum=' + cp.get('parcelNum')
               + '&ownerName=' + escape(parcelInfoStore.getAt(0).get('Owner Name'))
               + '&ownerAddress=' + escape(parcelInfoStore.getAt(0).get('Phys Addr1') + '<br>' + parcelInfoStore.getAt(0).get('Phys City'))
               + '&subtitle1=Average Soil Properties'
               + '&depthToHWTIn=' + Number(parcelInfoStore.getAt(0).get('Dep2HWT (in)')).toFixed(2)
               + '&depthToResLyrIn=' + Number(parcelInfoStore.getAt(0).get('Dep2ResLyr (in)')).toFixed(2)
               + '&hydSoilGroup=' + parcelInfoStore.getAt(0).get('Hyd Soil Group')
               + '&kSatInHr=' + Number(parcelInfoStore.getAt(0).get('KSat (in/hr)')).toFixed(2)
               + '&subtitle2=Land Use Areas'
               + '&impervAreaAc=' + Number(parcelInfoStore.getAt(0).get('Imperv Area (ac)')).toFixed(2)
               + '&uplandAreaAc=' + Number(parcelInfoStore.getAt(0).get('UpLand Area (ac)')).toFixed(2)
               + '&wetlandAreaAc=' + Number(parcelInfoStore.getAt(0).get('Wetland Area (ac)')).toFixed(2)
               + '&totalAreaAc=' + Number(parcelInfoStore.getAt(0).get('Total Area (ac)')).toFixed(2)
               + '&subtitle3=Total Phosphorus Loads'
               + '&pervLoadLbYr=' + Number(parcelInfoStore.getAt(0).get('Perv Load (lb/yr)')).toFixed(2)
               + '&impervLoadLbYr=' + Number(parcelInfoStore.getAt(0).get('Imperv Load')).toFixed(2)
               + '&totalLoadLbYr=' + Number(parcelInfoStore.getAt(0).get('Total Load (lb/yr)')).toFixed(2)
               + '&loadRemovedLbYr=' + cp.get('loadRemoved')
               + '&subtitle4=Stormwater Control Conceptual Design'
               + '&stormwaterControl=' + cp.get('stormwaterFull')
               + '&loadReductionPct=' + cp.get('pollution')
               + '&waterQualirtyDepthIn=' + Number(cp.get('wqd')).toFixed(2)
               + '&subtitle5=Estimated Stormwater Control Construction Costs'
               + '&siteConstraint=' + 'Partly developed area'
               + '&stormwaterControlUnitCostDollarLbYr=' + cp.get('unitCost')
               + '&stormwaterControlTotalCostDollar=' + cp.get('totalCost')
               + '&subtitle6=Estimated Trading Credit/Deficit'
               + '&loadCreditDeficitLbYr=' + cp.get('loadCreditDeficit')
               + '&creditUnitValueDollarLbYr=' + cp.get('unitCost')
               + '&title=SUMMARY AND CONCEPTUAL DESIGN'
               + '&file=solution'
            ,focusOnLoad : true
            ,title       : name
            ,width       : 510
            ,height      : 400
            ,y           : 75
            ,bodyStyle   : 'background:white'
            ,constrainHeader : true
            ,modal           : true
            ,title           : 'Summary and Conceptual Design'
          }).show();
        }
      }
  </script>
    <div id="site">
<?php include_once('header.php')?>

        <div id="content">
            <div class="home-screen clearfix">

                <div class="left-column" style="width: 500px;">
                    <h2 style="margin-bottom: 20px;">Results</h2>
                    <p>Congratulations, you have finished selecting a stormwater control!</p>
               			<p>Here is a summary of your design selection:</p>
               			<img src="images/<?php echo substr($_COOKIE['ys-stormwaterShort'],2)?>1.png" style="float: left; margin-right: 20px; width:105px" alt="" />
               			<p><strong><?php echo substr($_COOKIE['ys-stormwaterFull'],2)?></strong>. <?php echo substr($_COOKIE['ys-stormwaterDetails'],2)?></p>
               			<p style="float: left; margin-right: 20px;"><strong>Pollution Reduction:</strong>&nbsp;<?php echo substr($_COOKIE['ys-pollution'],2)?>%</p>
<?php
  $load = substr($_COOKIE['ys-loadCreditDeficit'],2);
  if ($load < 0) {
    echo "<p style=\"float: left;margin-right: 20px;\"><strong>Pollution Deficit:</strong>&nbsp;$load</p>";
  }
  else {
    echo "<p style=\"float: left;margin-right: 20px;\"><strong>Pollution Credit:</strong>&nbsp;+$load</p>";
  }
?>
               			<p style="margin-bottom: 20px;"><strong>Design Cost:</strong>&nbsp;<?php echo substr($_COOKIE['ys-totalCost'],2)?></p>
               			<p style="font-size: 16px;"><strong>Data and Design Presentation</strong></p>
               			<p>All the available data about your site, including detailed design information. This can be presented to an engineer or designer to help them design storm water controls.</p>
               			<a href="javascript:print()" ><img src="images/print_data_design-but.png" alt="" /></a>
               		</div>
               		<div class="right-column">
                          <table id="blue-box">
                            <tr><th><div id="step-five" class="progress-bar">&nbsp;</div></th></tr>
                            <tr><td>
                              <div id="small_map"><img src="<?php echo $thumbnail?>"></div>
<?php
  if ($isRegistered) {
?>
                              <p><label class="item first">Property Owner:</label><label><?php echo substr($_COOKIE['ys-parcelOwner_Name'],2)?></label></p>
<?php
}
else {
?>
                              <p><label class="item first">Property Address:</label><label><?php echo substr($_COOKIE['ys-parcelPhys_Addr1'],2).', '.substr($_COOKIE['ys-parcelPhys_City'],2)?></label></p>
<?php
}
?>
                              <p>
                                <label class="item">Area (Acres)</label><br>
                                <label class="item">Total:</label><label><?php echo sprintf("%.2f",substr($_COOKIE['ys-parcelTotal_Area_(ac)'],2))?></label><br>
                                <label class="item">Impervious:</label><label><?php echo sprintf("%.2f",substr($_COOKIE['ys-parcelImperv_Area_(ac)'],2))?></label>
                              </p>
                              <p><label class="item">Stormwater Control:</label><label><?php echo substr($_COOKIE['ys-stormwaterFull'],2)?></label></p>
<?php
  $load = substr($_COOKIE['ys-loadCreditDeficit'],2);
  if ($load < 0) {
    echo "<p><label class=\"item\">Pollution Deficit:</label><label><font color=\"red\">$load</font></label></p>";
  }
  else if ($load == 0 && $_COOKIE['ys-Regulated'] != 'True') {
    echo "<p><label class=\"item\">Pollution Credit:</label><label><font color=\"b8860b\">+$load</font></label></p>";
  }
  else {
    echo "<p><label class=\"item\">Pollution Credit:</label><label><font color=\"green\">+$load</font></label></p>";
  }
?>
                              <p><label class="item">Design Cost:</label><label><?php echo substr($_COOKIE['ys-totalCost'],2)?></label></p>
                              <p class="notice" id="notice"></p>
                            </td></tr>
                          </table>
               		</div>
               		<div style="padding-top: 40px; clear: both;">
               			<p>This concludes the recommended solutions sections of this website. Click Next to continue to the trading page.</p>
               			<a href="?page=introPollution"><img src="images/back_but.png" style="vertical-align: top; margin-top: 10px;" alt="Back" title="Back" /></a>
										<a href="?page=introTrading"><img src="images/next_but.png" style="vertical-align: top; margin-left: 570px; margin-top: 10px;" alt="Next" title="Next" /></a>						</div>

            </div>

        </div>
<?php include_once('footer.php')?>
    </div>
    <script type="text/javascript" src="./js/ext-3.4.0/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="./js/ext-3.4.0/ext-all.js"></script>
    <script type="text/javascript" src="./js/miframe/multidom.js"></script>
    <script type="text/javascript" src="./js/miframe/mif.js"></script>
    <script type="text/javascript" src="./js/calcs.js"></script>

</body>
